In the beginning, God created web 1.0 it was an information superhighway of documents connected together by hyperlinks and it was good. Around 2004 we saw the emergence of web 2.0 where more people started participating in the web through platforms like Facebook, Youtube, Twitter and many others. It led to massive centralised tech corporations that dominate the flow of information and money on the internet. We live in interesting times because we're at the tipping point of web 3.0, a decentralised but secure internet where people can exchange money and information without the need for an unnecessary middleman like a bank or tech corporation.
This blog is a complete introduction to the wild world of web 3.0. As an experienced developer, it's humbling to get into because it makes you feel like you know nothing again. We'll take a look at the ecosystem from a high level and try to answer most of the questions that you'll have when you first get into it.
How does a decentralized app or Dapps on the blockchain work?
Let's use the Ethereum blockchain as our example although there are many alternatives with different trade-offs out there, Ethereum is like a giant network of computers where all the participants agree on the same state of the data throughout the network. Now ether is the cryptocurrency on the Ethereum network which is used to create transactions that change the state of the data when you broadcast a transaction. You also offer up a small amount of ether which provides an incentive for another computer in the network to execute the transaction. This is also called a gas fee and conceptually it's similar to paying AWS for cloud computing resources. If you want things done faster you pay more gas. Normally when you build a web application you write some back-end code and then deploy it to a centralized server like AWS. But for a decentralized app on the blockchain, your backend code is contained in a smart contract usually written in the solidity language which is just an application that lives on the blockchain that can govern the behaviour between multiple accounts. A decentralized app also needs to have a front end which can be built just like a normal website except for the fact that user authentication works in a completely different way.
So, How does user identity work in a decentralized app?
Unlike web 2.0, in web 3.0 the end-user owns all of their data. There's no need for you, the developer, to collect a username and password. The end-user has a public wallet address that can receive payments and a private key that can sign transactions to send payments to someone else. The user can connect their wallet to a browser plugin like Metamask. Your friend application like a react app for example can then interact with that user's wallet to do something interesting in the UI, like purchase an NFT.
What does the front end of a web3 application look like?
For the most part, it's not much different than a normal web app, you'll likely use a UI library like React along with all your other favourite front-end tools. Things become different when we start talking about user authentication because like I mentioned earlier, the end-user uses a plugin like Metamask to make their public wallet details available to a decentralized app. Now the question becomes how do we as developers connect to Metamask, it's actually really easy because Metamask creates a global object on the browser window that we can use to access details about the wallet. Now figuring out what to do with this data is actually pretty complicated but luckily there are libraries out there to make our lives easier. The two most popular options are web3.js and ethers.js. They provide a javascript-based API making it much easier to interact with the end-user and smart contracts on the blockchain.
Here's an example of how the process might look we create a provider with the window Ethereum object which is used to then create a signer. You can think of that as the current user. We then connect to a smart contract and then change the state of it which will require the user's approval and is based on the logic and the smart contract itself. And that's all it really takes to initiate a transaction on the front end.
What does the back end look like in a web3 application?
Well, it's probably a lot different than what you're used to as an old-timey web developer. Instead of a server and database like PHP and MySQL, you'll be writing smart contracts. There are frameworks out there designed to streamline development. Two of the most popular options are Hardhat and Truffle. When you add them to your project they'll give you a place to write a smart contract in the solidity programming language. It's basically an object-oriented language designed specifically for writing smart contracts on the blockchain. That may sound intimidating but there's a project out there called OpenZeppelin that provides templates for writing smart contracts that comply with industry standards making it extremely easy to implement reliable code out of the gate. Now the other thing a development toolchain will do for you is to provide a script to deploy your smart contract to the blockchain. It's just a simple node script that signs a contract with your credentials and deploys it to an address on the blockchain.
How do I test a dapp with Ethereum?
Until now, we have no idea if this thing actually works. That's another thing that Hardhat and Truffle can help you out with. They can create a testing network on localhost and then generate a bunch of wallet addresses loaded up with fake crypto that you can use for testing in the browser. You can connect Metamask to your testing network instead of operating on the actual Ethereum network. In addition, if you're building a serious app you should consider writing automated tests for it and there's a library called Waffle that can help you do that.
Do I store all my data in the blockchain?
The answer is NO. It's neither efficient nor necessary to store everything in the blockchain and that's where off-chain storage comes in. In some cases, data might be too large to store on the blockchain or it might need to be modified or deleted which is not possible in a blockchain where all the data is read-only. The most common solution is the Interplanetary file system, IPFS. It's a decentralized way to share files very similar to the way BitTorrent works and there's also databases built on top of IPFS like OrbitDB and ThreadDB which is kind of like a peer-to-peer version of MongoDB.
Conclusion
If you've made it this far, you might be thinking web3 seems awesome but how do I get started. The easiest way to start messing around with smart contracts is with the Remix IDE. It's a browser-based tool that will handle all the compilation and everything for you so you don't have to mess around with any javascript. On Youtube, there are a couple of really good channels that I want to mention one is HashLips NFT for working with NFTs and the other one is Nader Dabit just for overall wisdom related to web3. I'm gonna go ahead and wrap things up here.
If you have more questions about web3 let me know in the comments and I'm curious to know if you think web 3 is the future or if it's just a big nothing burger. Thanks for reading to the end.
Post a Comment
Let's make it better!
Comment your thoughts...